﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="DHGMS Solutions" file="PipeDelimited.cs">
//   2004-2012 DHGMS Solutions. Some Rights Reserved. Licensed under GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Dhgms.TplHelper.Controller.Task.SqlExport
{
    using System.Data.SqlClient;

    using Dhgms.DataManager.Model.Info;

    using Kent.Boogaart.KBCsv;

    /// <summary>
    /// Exports a data reader to a pipe delimited file
    /// </summary>
    /// <typeparam name="TInformationClass">
    /// The information class that represents the output record format
    /// </typeparam>
    /// <typeparam name="TAdoNetHelperClass">
    /// The type for the ADO.NET helper class
    /// </typeparam>
    public abstract class PipeDelimited<TInformationClass, TAdoNetHelperClass> : Csv<TInformationClass, TAdoNetHelperClass>
        where TInformationClass : Base<TInformationClass>, new()
        where TAdoNetHelperClass : Dhgms.DataManager.Model.Helper.AdoNet.Base<TInformationClass>, new()
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="PipeDelimited{TInformationClass,TAdoNetHelperClass}"/> class. 
        /// </summary>
        /// <param name="taskName">
        /// Name of the task
        /// </param>
        /// <param name="connectionString">
        /// Database connection string
        /// </param>
        /// <param name="sqlCommand">
        /// The SQL command to execute
        /// </param>
        /// <param name="parameters">
        /// Parameters for the SQL command
        /// </param>
        /// <param name="outputFileName">
        /// The file we are saving to
        /// </param>
        protected PipeDelimited(
            string taskName, 
            string connectionString, 
            string sqlCommand, 
            SqlParameter[] parameters, 
            string outputFileName)
            : base(taskName, connectionString, sqlCommand, parameters, outputFileName)
        {
        }

        #endregion

        #region Methods

        /// <summary>
        /// Used to change the output format, if needed
        /// </summary>
        /// <param name="output">
        /// output object
        /// </param>
        protected override void OnOverrideOutputFormat(CsvWriter output)
        {
            output.ValueSeparator = '|';
            output.ValueDelimiter = '"';
        }

        #endregion
    }
}